Awesomepeople = {
    init : function() {
        Awesomepeople.createNewAchievement();
    //		Awesomepeople.ajaxLogin("login.php", {
    //			username : "admin",
    //			password : "12345",
    //			from: "awesomepeople"
    //		});
    },
    initLogin : function() {
        $("#login_button").click(function() {
            var action = $("#form").attr('action'), formData = Awesomepeople.getLoginData();
            ajaxLogin(action, formData);
        });
    },
    getLoginData : function() {
        var formData = {
            username : $("#username").val(),
            password : $("#password").val(),
            is_ajax : 1
        };
        return formData;
    },
    ajaxLogin : function(action, data) {
        $.ajax({
            type : "POST",
            url : action,
            data : data,
            success : function(response) {
                response = JSON.parse(response);
                if(response['response'] == 'success') {
                    console.log("You have logged in successfully!");
                // for(var i = response['achievements'].length - 1; i >= 0; i--) {
                // Awesomepeople.createAchievement(response['achievements'][i]);
                // }
					
                }

                // $("#form").slideUp('slow', function() {
                //
                // $("#message").html("<p class='success'>You have logged in successfully!</p>");
                // });
                else {
                    console.log(response['message']);
                    $("#message").html("<p class='error'>Invalid username and/or password.</p>");
                }
            }
        });
    },
    createAchievement : function(achievement) {
          var col = achievement['done'] == 1 ? 'left' : 'right';
        $("#"+col+"_achievement_ul").append("<li class='"+col+"_achievement_li'><div class='achievement-test'>"+achievement['name']+" "+achievement['description']+"</div></li>")
    },
       
    createNewAchievement : function() {
        var achievement = [];
        achievement['name'] = "<input name='newName' type='text' value='Nome de Teste'  id='new_name'/>";
        achievement['description'] =  "<input name='newDescription' type='text' value='Descri??o de Teste' id='new_description'/>";
        $("#right_achievement_ul").prepend("<li id='new_archivement' class='right_achievement_li'><div class='achievement_right'><spam class='achievement_name'>"+achievement['name']+"</spam><spam class='achievement_description'>"+achievement['description']+"</spam></div></li>");
    },
        
        
// Ajax Shit //
    postNewArchievement : function(param) {
         var data = {
            name : $("#new_name").val(),
            description : $("#new_description").val(),
            createArchievement: true
        };
        
        $.ajax({
            type : "POST",
            url : 'ajax.php',
            data : data,
            success : function(response) {
//                response = JSON.parse(response);
//                if(response['response'] == 'success') {
                    param.sucess(response);
//               }
//                else {
//                    console.log(response['message']);
//                    $("#message").html(response['message']);
//                }
            }
        });
    },
    
    finishAchievement : function(param) {
         var data = {
            idAchievement : param.idArchievement,
            finishAchievement: true
        };
        
        $.ajax({
            type : "POST",
            url : 'ajax.php',
            data : data,
            success : function(response) {
//                response = JSON.parse(response);
//                if(response['response'] == 'success') {
                    param.sucess(response);
//               }
//                else {
//                    console.log(response['message']);
//                    $("#message").html(response['message']);
//                }
            }
        });
    }
};
